Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

selectn

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

selectn

Resolves deeply-nested object properties via dot or bracket-notation for Node.js and the browser.

  • 0.9.6
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is selectn?

The selectn npm package is a utility for safely accessing deeply nested properties in JavaScript objects. It allows you to use a string path to retrieve the value at that path, returning undefined if any part of the path does not exist.

What are selectn's main functionalities?

Accessing Nested Properties

This feature allows you to access deeply nested properties within an object using a string path. If the path does not exist, it returns undefined instead of throwing an error.

const selectn = require('selectn');
const obj = { a: { b: { c: 42 } } };
const value = selectn('a.b.c', obj);
console.log(value); // 42

Handling Non-Existent Paths

This feature demonstrates how selectn handles non-existent paths gracefully by returning undefined instead of throwing an error.

const selectn = require('selectn');
const obj = { a: { b: { c: 42 } } };
const value = selectn('a.b.x', obj);
console.log(value); // undefined

Default Values

This feature shows how you can provide a default value when the path does not exist by using the logical OR operator.

const selectn = require('selectn');
const obj = { a: { b: { c: 42 } } };
const value = selectn('a.b.x', obj) || 'default';
console.log(value); // 'default'

Other packages similar to selectn

Keywords

FAQs

Package last updated on 12 Nov 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc